<?php
namespace Admin\Controller;
use Think\Controller;
class FeeController extends Controller {
    protected function _initialize() {
        //===权限验证======
        if (!session('admin')) {
            $this->error('请先登录!', U('Index/index'));
        }
        $admin = session('admin');
        $this->assign('admin', $admin);
        //===系统信息======
        $system = D('System')->find(1);
        $this->assign('system', $system);
    }
    public function FeeR($number = '', $grade_id = '', $class_id = '', $term_id = '',$major_id='',$identity='') {
        if ($term_id == '') {
            //如果没选择学期，默认是系统设置的当前学期
            $system = D('System')->find(1);
            $term_id = $system['term_id'];
        }
        //===header信息处理======
        $header = array(
            'sup'=>array(
                'name'=>'交费管理',
                'fee'=>'active',
            ),
            'sub'=>array(
                'name'=>'交费列表',
                'fee_r'=>'active',
            ),
            'icon'=>'icon-usd',
            'url'=>'FeeR',
        );
        $this->assign('header', $header);
        //查询信息
        $findFlag = 0;
        
        if (($number != '')&&($findFlag == 0)) {
            $student = M('Student')->where(['number'=>$number])->find();
            $findMap['student_id'] = ['eq', $student['id']];
            $findFlag = 1;
        }
        if (($identity!= '')&&($findFlag == 0)) {
            $student = M('Student')->where(['identity'=>$identity])->find();
            $findMap['student_id'] = ['eq', $student['id']];
        }
        if (($grade_id != '')&&($findFlag == 0)) {
            $findMap['grade_id'] = ['LIKE', '%'.$grade_id.'%'];
        }
        if (($class_id != '')&&($findFlag == 0)) {
            $findMap['class_id'] = ['LIKE', '%'.$class_id.'%'];
        }
        if (($term_id != '')&&($findFlag == 0)) {
            $findMap['term_id'] = ['LIKE', '%'.$term_id.'%'];
        }
        if (($major_id != '')&&($findFlag == 0)) {
            $findMap['major_id'] = ['LIKE', '%'.$major_id.'%'];
        }
        //===分页获取信息======
        $model = M('Fee');
        $count = $model->where($findMap)->count();
        $page = new \Think\AdminPage($count,C('PAGE_NUM'));
        $show = $page->show();
        $list = $model->where($findMap)->order('id')->limit($page->firstRow.','.$page->listRows)->select();
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $student = M('Student')->select();
        $this->assign('student', $student);
        
        $grade = M('Grade')->select();
        $this->assign('grade', $grade);
        if ($major_id != ''){
            $class = M('Class')->where(['major_id'=>$major_id])->select();
            $this->assign('class', $class);
        }else{
            $class = M('Class')->select();
            $this->assign('class', $class);
        }
       
        $term = M('Term')->select();
        $this->assign('term', $term);
        $major = M('Major')->select();
        $this->assign('major', $major);
        
        $this->display('fee_r');
    }
    public function FeeC() {
        if (IS_POST) {
            $model = D('Fee');
            if (!$model->create()) {
                $this->error($model->getError());
                return false;
            }
            $model->add();
            $this->success('新增成功!', U('Fee/FeeR'));
        }
        //===header信息处理======
        $header = array(
            'sup'=>array(
                'name'=>'交费管理',
                'fee'=>'active',
            ),
            'sub'=>array(
                'name'=>'新增交费',
                'fee_c'=>'active',
            ),
            'icon'=>'icon-usd',
            'url'=>'FeeR',
        );
        $this->assign('header', $header);
        
        $student = M('Student')->select();
        $this->assign('student', $student);
        
        $grade = M('Grade')->select();
        $this->assign('grade', $grade);
        
        $class = M('Class')->select();
        $this->assign('class', $class);
        
        $term = M('Term')->select();
        $this->assign('term', $term);
        $major = M('Major')->select();
        $this->assign('major', $major);
        
        $this->display('fee');
    }
    public function FeeU($id = 0) {
        $model = D('Fee');
        if (IS_POST) {
            $_POST['id'] = $id;
            if ($_POST['over'] > $_POST['should']) {
                $this->error('实交学费不能高出应交学费，请检查!');
            }
            if (!$model->create()) {
                $this->error($model->getError());
                return false;
            }
            $model->save();
            $this->success('修改成功!', U('Fee/FeeR'));
        }
        $Fee = $model->getById($id);
        if (!$Fee) {
            $this->error('非法操作!');
            return false;
        }
        $this->assign('model', $Fee);
        //===header信息处理======
        $header = array(
            'sup'=>array(
                'name'=>'交费管理',
                'fee'=>'active',
            ),
            'sub'=>array(
                'name'=>'修改交费',
                'fee_u'=>'active',
            ),
            'icon'=>'icon-usd',
            'url'=>'FeeR',
        );
        $this->assign('header', $header);
        
        $student = M('Student')->select();
        $this->assign('student', $student);
        
        $grade = M('Grade')->select();
        $this->assign('grade', $grade);
        
        $class = M('Class')->select();
        $this->assign('class', $class);
        
        $term = M('Term')->select();
        $this->assign('term', $term);
        $major = M('Major')->select();
        $this->assign('major', $major);
        
        $this->display('fee');
    }
    public function delete() {
        if (IS_POST) {
            $id = I('post.id');
            $model = D('Fee');
            $model->delete($id);
            $data['info'] = '删除成功!';
            $data['status'] = 1;
            $this->ajaxReturn($data, 'JSON');
        }
    }
    public function sync() {
        //student
        $students = D('Student')->select();
        //term
        $term = D('Term')->select();
        //tuition
        $tuitions = D('Tuition')->select();
        foreach ($tuitions as $tuition) {
            foreach ($students as $student) {
                unset($whereData);
                $whereData['student_id'] = $student['id'];
                $whereData['term_id'] = $tuition['term_id'];
                $whereData['tuition_id'] = $tuition['id'];
                $fee = D('Fee')->where($whereData)->find();
                if (!$fee) {
                    unset($data);
                    $data['student_id'] = $student['id'];
                    $data['grade_id'] = $student['grade_id'];
                    $data['major_id'] = $student['major_id'];
                    $data['class_id'] = $student['class_id'];
                    $data['class_id'] = $student['class_id'];
                    $data['term_id'] = $tuition['term_id'];
                    $data['should'] = $tuition['money'];
                    $data['tuition_id'] = $tuition['id'];
                    D('Fee')->add($data);
                }
            }
        }
        $this->success('同步成功!');
    }
}
<div class="col-md-3 find-input-div">
                        <input type="text" class="col-md-12 find-input" name="number" id="number" value="{$_GET[number]}" placeholder="学生编号"/>
                    </div>
                    <div class="col-md-3 find-input-div">
                        <input type="text" class="col-md-12 find-input" name="identity" id="identity" value="{$_GET[identity]}" placeholder="学生身份证号"/>
                    </div>